1. Field of the Invention
The present invention relates generally to a distribution system of digital contents, i.e., digitally encoded published materials. More particularly, the invention relates to a method for dynamically converting the byte-ordering of a data structure in a digital content from one format to a different format.
2. Description of Related Art
Advances in computer and communication technology have provided the consumers a convenient and economical means to access information in a variety of media. One particular area of information access is the electronic books. An electronic book is a viewing device that receives printed materials in the form of digital data downloaded from an information network. A user of an electronic book can read downloaded contents of books and printed materials subscribed from a participating bookstore at his or her own convenience without the need to purchase the printed copies of the books.
An electronic book, or any other viewing device, has persistent memory, such as a hard disk or a flash random-access-memory (RAM), to store the downloaded digital contents and constitutes a particular processor platform.
Digital contents stored as binary data in persistent memory of a viewing device must be readable in the native byte-ordering format of the processor of the viewing device. For performance reasons, certain processors require the byte-ordering of numeric values to be in specific formats. These formats may be different for different types of processors. For example, for use on a Motorola 680x0 chip, the 2-byte hexadecimal number 3AF7 is stored in RAM as: 3A in byte 1, F7 in byte 2. For use on an Intel processor, the same number is stored in RAM as: F7 in byte 1, 3A in byte 2. The Motorola chip format is called big endian format, and the Intel chip format is called little endian format. The conversion of raw numerical data from one format to the other is further complicated by the fact that the byte-swapping must depend on individual data element sizes. Without knowing the individual data element sizes, it is not possible to convert raw binary numerical data from one format to the other. For instance, two 2-byte numbers are indistinguishable from one 4-byte number. Consider the big endian data ABCD where A, B, C and D are bytes. This data may be two 2-byte numbers, namely, AB and CD, or it may be a single 4-byte number ABCD. Since byte swapping must be done for individual numbers, the resulting little endian data are either BADC if the big endian data are two 2-byte numbers, or DCBA if the big endian data is a single 4-byte number.
For optimal performance, binary data should be stored in the endian format of the final target processor platform for which it is created. However, this is not possible if there is more than one target processor platform and the platforms are not compatible. For example, in a digital content distribution system which includes a virtual bookstore and two different groups of viewing devices which run on two incompatible types of processors, a digital content stored in one endian format at the virtual bookstore can be directly used by one group of viewing devices, but must be converted to a different endian format to be used by the other group. Performing conversion of byte-ordering at the viewing device level is time-consuming and prone to errors, specially when the data structure has a complex combination of data types and contains nested lists of other structures. In addition, a change to a data structure will require every user of that structure to change its conversion.
Therefore, currently, there is a need for an efficient method to dynamically convert the byte-ordering of a data structure from one endian format to another endian format for use on a different processor platform.
The present invention is a method for dynamically converting the byte-ordering of a data structure of a resource type from a first format to a second format, the first format being incompatible with the second format. The method comprises the following steps: (a) creating a template which corresponds to the data structure of the resource type, the template having a structure in a third format which is compatible with the first and second formats; (b) linking the template to the resource type; and (c) converting automatically the byte-ordering of the data structure of the resource type from the first format to the second format using the template.